home *** CD-ROM | disk | FTP | other *** search
- /* File: LibraryManagerClasses.h
-
- Contains: Declarations for LibraryManager classes
-
- Copyright: © 1991-1992 by Apple Computer, Inc., all rights reserved.
-
-
- */
-
- #ifndef __LIBRARYMANAGERCLASSES__
- #define __LIBRARYMANAGERCLASSES__
-
- #ifndef __LIBRARYMANAGER__
- #include <LibraryManager.h>
- #endif
-
- /*******************************************************************************
- ** Forward class declarations
- ********************************************************************************/
-
- class TFormattedStream; // not actually defined yet
- class TSemaphore;
-
- class TMatchObject;
- class THashObject;
- class TIterator;
- class TCollection;
- class TLink;
- class TPriorityLink;
- class TSimpleList;
- class TLinkedList;
- class TPriorityList;
- class TListIterator;
- class TArray;
- class TArrayIterator;
-
- class TOperation;
- class TScheduler;
- class TPriorityScheduler;
- class TSerialScheduler;
- class TThreadScheduler;
- class TTaskScheduler;
- class TInterruptScheduler;
- class TTimeScheduler;
-
- class TNotifier;
- class TProcNotifier;
- class TMethodNotifier;
-
- class TMemoryPool;
- class TStandardPool;
- class TChunkyPool;
- class TGrowOperation;
- class TPoolNotifier;
-
- class TArbitrator;
- class TTokenNotification ;
- class TToken;
- class TRequestToken;
-
- class TClassInfo;
- class TLibraryFile;
-
- class TBitmap;
- class TDoubleLong;
- class THashDoubleLong;
- class TTime;
- class TMicroseconds;
- class TMilliseconds;
- class TSeconds;
- class TTimeStamp;
- class TStopwatch;
-
- class TTraceLog;
-
- class TException ;
-
- /*******************************************************************************
- ** Some typedefs
- ********************************************************************************/
-
- typedef unsigned long EventCode;
- typedef void* GlobalWorld;
-
- typedef void (*ProcessProc)(TOperation*);
-
- // Below is a typedef for a pointer to a notify method for an object. Ignore the
- // fact the the typedef claims that it needs to be a TDynamic method. It can be
- // any kind of class. The only caveat is that if the NotifyProc is a virtual
- // function, the vtable for the object must be the first field of the object.
- // You can force the vtable to be first by creating a base class that has atleast
- // one virtual function and no data members, like TDynamic does.
- typedef void (TDynamic::*NotifyMethod)(EventCode, OSErr, void*);
- typedef void (*NotifyProc)(void* refPtr, EventCode, OSErr, void*);
-
- /*******************************************************************************
- ** Miscellaneous constant
- ********************************************************************************/
-
- #ifndef kInvalidWorld
- #define kInvalidWorld ((GlobalWorld)0)
- #endif
-
- /*******************************************************************************
- ** Some constants needed for Notification
- ********************************************************************************/
-
- const EventCode kTokenNotification = 0x40000001;
- const EventCode kLowPoolMemoryEvent = 0x40000002;
- const EventCode kHighPoolMemoryEvent= 0x40000003;
- const EventCode kDownsizePoolEvent = 0x40000004;
-
- /*******************************************************************************
- ** Some "C" Global routines
- ********************************************************************************/
-
- extern "C"
- {
- TStandardPool* GetLocalPool();
- void SetLocalPool(TStandardPool*);
- TStandardPool* GetClientPool();
- TStandardPool* GetDefaultPool();
- void SetDefaultPool(TStandardPool*);
- TStandardPool* GetSystemPool();
-
- TTraceLog* GetGlobalTraceLog();
- void SetGlobalTraceLog(TTraceLog*);
- void Trace(const char *formatStr, ...);
-
- TArbitrator* GetGlobalArbitrator();
- TTaskScheduler* GetGlobalTaskScheduler();
- };
-
- /*******************************************************************************
- ** TSemaphore class
- **
- ** Since threads don't really exist on the Macintosh, Semaphores are
- ** done by shutting interrupts off to guarantee exclusivity. Therefore,
- ** the rule is - never hold a semaphore very long, since on the Macintosh
- ** it will degrade performance if you do.
- ********************************************************************************/
-
- #define kTSemaphoreID "!$sema"
-
- class TSemaphore : public TDynamic
- {
- public:
- TSemaphore();
- virtual ~TSemaphore();
-
- virtual void Grab();
- virtual void Release();
- virtual Boolean GrabNoWait();
-
- private:
- TSemaphore(const TSemaphore&);
- void operator=(const TSemaphore&);
-
- short fSaveLevel;
- short fCount;
- };
-
- /*******************************************************************************
- ** CLASS TMatchObject
- **
- ** This object is the base class for any object which "knows" how
- ** to hash a specific object, as well as how to compare a
- ** 2nd object to the specific object.
- ********************************************************************************/
-
- #define kTMatchObjectID "!$mobj"
-
- class TMatchObject : public TDynamic
- {
- public:
- virtual ~TMatchObject();
-
- // Default implementation is to return 0
- virtual unsigned long Hash() const;
- // Default implementation is to compare
- // address of "this" with address of the object
- virtual short Compare(const void*) const;
- // Default implementation is to call Compare
- virtual Boolean IsEqual(const void*) const;
-
- protected:
- TMatchObject();
- };
-
- /*******************************************************************************
- ** CLASS THashObject
- **
- ** This object is the base class for any object which "knows" how
- ** to hash another object.
- ********************************************************************************/
-
- #define kTHashObjectID "!$hobj"
-
- class THashObject : public TDynamic
- {
- public:
- virtual ~THashObject();
-
- virtual unsigned long Hash(const void*) const = 0;
-
- protected:
- THashObject();
- };
-
- /*******************************************************************************
- ** CLASS TIterator
- **
- ** This class Iterates through a collection of objects. Since
- ** collections are "thread-safe", when the Next() method returns
- ** NULL, call IterationComplete(). If it returns true, then you were
- ** returned NULL because the iterator was done. Otherwise, you were
- ** returned NULL because the underlying collection changed.
- ** RemoveCurrentObject will return false if the collection changed
- ** before the remove could be done.
- ********************************************************************************/
-
- #define kTIteratorID "!$iter"
-
- class TIterator : public TDynamic
- {
- public:
- virtual ~TIterator();
-
- virtual void Reset() = 0;
- virtual void* Next() = 0;
-
- virtual Boolean IterationComplete() const = 0;
- virtual Boolean RemoveCurrentObject() = 0;
-
- void SetMatchObject(TMatchObject* theMatcher);
- TMatchObject* GetMatchObject() const;
-
- protected:
- TIterator();
- private:
- TMatchObject* fMatcher;
- };
-
- /* -------------------------------------------------------------------------
- inline methods for TIterator
- ------------------------------------------------------------------------- */
- inline void TIterator::SetMatchObject(TMatchObject* theMatcher)
- {
- fMatcher = theMatcher;
- }
-
- inline TMatchObject* TIterator::GetMatchObject() const
- {
- return fMatcher;
- }
-
- /*******************************************************************************
- ** CLASS TCollection
- **
- ** This class defines the framework for all collections.
- ********************************************************************************/
-
- #define kTCollectionID "!$coll"
-
- class TCollection : public TDynamic
- {
- public:
- virtual ~TCollection();
-
- size_t Count() const;
- Boolean IsEmpty() const;
- virtual TIterator* CreateIterator(TStandardPool*) const = 0;
-
- virtual OSErr Add(void*);
- virtual OSErr AddUnique(void*, const TMatchObject&);
- virtual OSErr AddUnique(void*);
-
- virtual void RemoveAll();
- virtual void DeleteAll(Boolean isTDynamic = true);
- virtual void* Remove(const TMatchObject&) = 0;
- virtual void* Member(const TMatchObject&) = 0;
- virtual Boolean Remove(void*) = 0;
- virtual Boolean Member(const void*) = 0;
-
- virtual void* GetIndexedObject(size_t) const;
- void* operator[](size_t);
-
- long GetSeed() const;
- void Grab();
- void Release();
-
- protected:
- TCollection();
- virtual OSErr PrivateAdd(void*, long) = 0;
- virtual void KillAll(Boolean ifDel, Boolean isTDynamic = true) = 0;
-
- long fSeed;
- size_t fCount;
- TSemaphore fSemaphore;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TCollection
- ----------------------------------------------------------------- */
-
- inline size_t TCollection::Count() const
- {
- return fCount;
- }
-
- inline Boolean TCollection::IsEmpty() const
- {
- return fCount == 0;
- }
-
- inline void* TCollection::operator[](size_t idx)
- {
- return GetIndexedObject(idx);
- }
-
- inline long TCollection::GetSeed() const
- {
- return fSeed;
- }
-
- inline void TCollection::Grab()
- {
- (&fSemaphore)->Grab();
- }
-
- inline void TCollection::Release()
- {
- (&fSemaphore)->Release();
- }
-
- /*******************************************************************************
- ** CLASS TLink
- **
- ** This class implements a link object which can be placed on a linked
- ** list. It is totally non-virtual since it is a trivial class and
- ** to keep it at 8 bytes in size.
- ********************************************************************************/
-
- class TLink
- {
- public:
- TLink(void* value);
- TLink(TLink* link, void* value);
- TLink(Boolean);
- TLink();
- ~TLink();
-
- void* operator new(size_t size, TMemoryPool*); // default size, from a pool
- void* operator new(size_t); // from default pool
- void operator delete(void* mem) {SLMDeleteOperator(mem);};
-
- void SetNext(TLink* link);
- TLink* GetNext() const;
-
- void* GetValue() const;
- void SetValue(void*);
-
- void Append(TLink* newLink); // append newLink after this
- void Remove(TLink* previous); // remove nextLink from list
-
- private:
- TLink* fNext;
- void* fValue;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TLink
- ----------------------------------------------------------------- */
-
- inline void* TLink::operator new(size_t size, TMemoryPool* thePool)
- {
- return SLMNewOperator(size, thePool);
- }
-
- inline void* TLink::operator new(size_t size)
- {
- return SLMNewOperator(size, NULL);
- }
-
- inline TLink::TLink(Boolean)
- {}
-
- inline TLink::TLink()
- {
- fNext = NULL;
- fValue = NULL;
- }
-
- inline TLink::TLink(void* value)
- {
- fNext = NULL;
- fValue = value;
- }
-
- inline TLink::TLink(TLink* link, void* value)
- {
- fNext = link;
- fValue = value;
- }
-
- inline TLink::~TLink()
- {
- fNext = NULL;
- fValue = NULL;
- }
-
- inline void TLink::SetNext(TLink* link)
- {
- fNext = link;
- }
-
- inline TLink* TLink::GetNext() const
- {
- return fNext;
- }
-
- inline void* TLink::GetValue() const
- {
- return fValue;
- }
-
- inline void TLink::SetValue(void* obj)
- {
- fValue = obj;
- }
-
- inline void TLink::Append(TLink* newLink)
- {
- newLink->SetNext(fNext);
- fNext = newLink;
- }
-
- inline void TLink::Remove(TLink* previous)
- {
- TLink* link = previous->GetNext();
- previous->SetNext(fNext);
- link->SetNext(NULL);
- }
-
- /*******************************************************************************
- ** CLASS TPriorityLink
- **
- ** This class implements a link object which can be placed on a linked
- ** list, and can hold a timer or priority value.
- ********************************************************************************/
-
- const unsigned long kNormalPriority = ((unsigned long)-1L) >> 1;
- const unsigned long kHighestPriority = 0;
- const unsigned long kLowestPriority = (unsigned long)-1L;
- const unsigned long kToLowerPriority = 1;
-
- class TPriorityLink : public TLink
- {
- public:
- TPriorityLink(Boolean);
- TPriorityLink(void* value);
- TPriorityLink(TLink* link, void* value);
- TPriorityLink();
-
- void SetPriority(unsigned long);
- unsigned long GetPriority() const;
-
- private:
- unsigned long fPriority;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TPriorityLink
- ----------------------------------------------------------------- */
-
- inline TPriorityLink::TPriorityLink(Boolean val) : TLink(val)
- {}
-
- inline TPriorityLink::TPriorityLink()
- {
- fPriority = kNormalPriority;
- }
-
- inline TPriorityLink::TPriorityLink(TLink* link, void* value) :
- TLink(link, value)
- {
- fPriority = kNormalPriority;
- }
-
- inline TPriorityLink::TPriorityLink(void* value) : TLink(value)
- {
- fPriority = kNormalPriority;
- }
-
- inline void TPriorityLink::SetPriority(unsigned long pri)
- {
- fPriority = pri;
- }
-
- inline unsigned long TPriorityLink::GetPriority() const
- {
- return fPriority;
- }
-
- /*******************************************************************************
- ** CLASS TSimpleList
- **
- ** This class implements a simple linked list, which can have objects added
- ** at the front or the back of the list.
- ********************************************************************************/
-
- #define kTSimpleListID "!$slst"
-
- class TSimpleList : public TCollection
- {
- friend class TListIterator;
-
- public:
- TSimpleList();
- TSimpleList(TMemoryPool*);
- TSimpleList(TSimpleList*);
- virtual ~TSimpleList();
-
- // TCollection overrides
-
- virtual TIterator* CreateIterator(TStandardPool*) const;
-
- virtual void* Remove(const TMatchObject&);
- virtual void* Member(const TMatchObject&);
- virtual Boolean Remove(void*);
- virtual Boolean Member(const void*);
-
- // New methods
-
- virtual TLink* MemberLink(const void*);
- virtual TLink* MemberLink(const TMatchObject&);
- virtual TLink* RemoveLink(void*);
- virtual TLink* RemoveLink(const TMatchObject&);
-
- virtual TLink* FirstLink() const;
- virtual TLink* LastLink() const;
- virtual TLink* RemoveFirstLink();
- virtual TLink* RemoveLastLink();
- virtual void AddLinkFirst(TLink*);
- virtual void AddLinkLast(TLink*);
-
- virtual void* First() const;
- virtual void* Last() const;
- virtual void* RemoveFirst();
- virtual void* RemoveLast();
- virtual OSErr AddFirst(void*);
- virtual OSErr AddLast(void*);
-
- void SetLinkPool(TMemoryPool*);
- TMemoryPool* GetLinkPool() const;
-
- protected:
- virtual OSErr PrivateAdd(void*, long);
- virtual void KillAll(Boolean ifDel, Boolean isTDynamic = true);
- virtual TLink* PrivateFind(const void*, const TMatchObject*, TLink**) const;
-
- private:
- TSimpleList(const TSimpleList&);
- void operator=(const TSimpleList&);
-
- protected:
-
- TLink* fList;
- TLink* fLastInList;
- TMemoryPool* fLinkPool;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TSimpleList
- ----------------------------------------------------------------- */
-
- inline void TSimpleList::SetLinkPool(TMemoryPool* thePool)
- {
- fLinkPool = thePool;
- }
-
- inline TMemoryPool* TSimpleList::GetLinkPool() const
- {
- return fLinkPool;
- }
-
- /*******************************************************************************
- ** CLASS TLinkedList
- **
- ** This class adds the ability to do things with a linked list based on
- ** "after" or "before" rules.
- ********************************************************************************/
-
- #define kTLinkedListID "slm:coll$llst"
-
- class TLinkedList : public TSimpleList
- {
- public:
- TLinkedList();
- TLinkedList(TMemoryPool*);
- TLinkedList(TSimpleList*);
- virtual ~TLinkedList();
-
- // New methods
-
- virtual void* After(const void* obj) const;
- virtual void* After(const TMatchObject&) const;
- virtual void* Before(const void* obj) const;
- virtual void* Before(const TMatchObject&) const;
-
- virtual Boolean AddLinkAfter(TLink*, const TMatchObject&);
- virtual Boolean AddLinkAfter(TLink*, const void* obj);
- virtual Boolean AddLinkBefore(TLink*, const TMatchObject&);
- virtual Boolean AddLinkBefore(TLink*, const void* obj);
- virtual OSErr AddAfter(void*, const TMatchObject&);
- virtual OSErr AddAfter(void*, const void* obj);
- virtual OSErr AddBefore(void*, const TMatchObject&);
- virtual OSErr AddBefore(void*, const void* obj);
-
- private:
- TLinkedList(const TLinkedList&);
- void operator=(const TLinkedList&);
- };
-
- /*******************************************************************************
- ** CLASS TPriorityList
- **
- ** This class implements a list where objects are sorted in order of a
- ** priority.
- ********************************************************************************/
-
- #define kTPriorityListID "!$plst"
-
- class TPriorityList : public TSimpleList
- {
- public:
- TPriorityList();
- TPriorityList(TMemoryPool*);
- TPriorityList(TPriorityList*);
- virtual ~TPriorityList();
-
- // TLinkedList overrides
-
- virtual OSErr AddFirst(void*);
- virtual OSErr AddLast(void*);
- virtual void AddLinkFirst(TLink*);
- virtual void AddLinkLast(TLink*);
-
- // New methods
-
- virtual OSErr AddPrioritized(void*, unsigned long pri);
- virtual void AddLink(TPriorityLink*);
-
- private:
- TPriorityList(const TPriorityList&);
- void operator=(const TPriorityList&);
- virtual OSErr PrivateAdd(void*, long);
- };
-
- /*******************************************************************************
- ** CLASS TListIterator
- **
- ** This iterator is used to iterate all collection classes descending from
- ** TSimpleList.
- ********************************************************************************/
-
- #define kTListIteratorID "!$litr"
-
- class TListIterator : public TIterator
- {
- public:
- TListIterator(TSimpleList*);
- virtual ~TListIterator();
-
- virtual TLink* GetCurrentLink() const;
-
- // TIterator Overrides
-
- virtual void Reset();
- virtual void* Next();
-
- virtual Boolean IterationComplete() const;
- virtual Boolean RemoveCurrentObject();
-
- // New methods
- void SetList(TSimpleList*);
-
- private:
- TListIterator(const TListIterator&);
- void operator=(const TListIterator&);
-
- virtual TLink* NextLink();
-
- TSimpleList* fList;
- TLink* fPrevLink;
- TLink* fCurLink;
- long fSeed;
- Boolean fComplete;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TListIterator
- ------------------------------------------------------------------------- */
-
- inline void TListIterator::SetList(TSimpleList* list)
- {
- fList = list;
- Reset();
- }
-
- /*******************************************************************************
- ** CLASS TArray
- **
- ** This class implements an array collection, where objects can be efficiently
- ** looked at by index, and are added to the end of the array. Deleting objects
- ** moves all higher-indexed objects down by 1 index number.
- ********************************************************************************/
-
- #define kTArrayID "slm:coll$arry"
-
- class TArray : public TCollection
- {
- friend class TArrayIterator;
-
- public:
- TArray();
- TArray(size_t size, TStandardPool* = NULL,
- short growBy = 0);
- virtual ~TArray();
-
- TStandardPool* GetGrowPool() const;
-
- // TCollection overrides
-
- virtual TIterator* CreateIterator(TStandardPool*) const;
-
- virtual Boolean Remove(void*);
- virtual void* Remove(const TMatchObject&);
- virtual Boolean Member(const void*);
- virtual void* Member(const TMatchObject&);
-
- virtual void* GetIndexedObject(size_t) const;
-
- private:
- TArray(const TArray&);
- void operator=(const TArray&);
- void InitArray(size_t size, TStandardPool*, short growBy);
-
- protected:
- virtual void* MemberIndex(const void*, const TMatchObject*, size_t*);
- virtual void* PrivateRemove(void*, const TMatchObject*);
- virtual OSErr PrivateAdd(void*, long);
- virtual void KillAll(Boolean ifDel, Boolean isTDynamic = true);
- virtual Boolean Grow();
-
- void** fArray; // memory allocated for the array
- size_t fSize; // current size of the array
- long fGrowBy; // size to grow by if array is full
- };
-
- /*******************************************************************************
- ** CLASS TArrayIterator
- **
- ** This class Iterates through a TArray collection
- ********************************************************************************/
-
- #define kTArrayIteratorID "slm:coll$aitr"
-
- class TArrayIterator : public TIterator
- {
- public:
- TArrayIterator(TArray*);
- virtual ~TArrayIterator();
-
- virtual void Reset();
- virtual void* Next();
-
- virtual Boolean IterationComplete() const;
- virtual Boolean RemoveCurrentObject();
-
- private:
- TArrayIterator(const TArrayIterator&);
- void operator=(const TArrayIterator&);
-
- private:
- TArray* fArray;
- size_t fCurIdx;
- long fSeed;
- Boolean fComplete;
- };
-
- /**********************************************************************
- ** CLASS TOperation
- ***********************************************************************/
-
- #define kTOperationID "!$oper"
-
- class TOperation : public TDynamic
- {
- public:
- TOperation();
- TOperation(long creatorData);
- TOperation(void* creatorPtr);
- TOperation(ProcessProc, long creatorData);
- TOperation(ProcessProc, void* creatorPtr);
- TOperation(const TOperation&);
- virtual ~TOperation();
-
- TPriorityLink* GetLink();
-
- virtual void Reset();
- virtual void Process();
-
- // New Methods
-
- void SetProcessProc(ProcessProc);
- ProcessProc GetProcessProc() const;
-
- // Timer and Priority are just 2 different ways
- // of looking at the same field.
-
- void SetTime(const TTime&);
- void SetTime(unsigned long msecs);
- void SetPriority(unsigned long pri);
- unsigned long GetTime() const;
- unsigned long GetPriority() const;
-
- // CreatorData and CreatorPtr are just 2 different ways
- // of looking at the same field.
-
- void* GetCreatorPtr() const;
- long GetCreatorData() const;
- void SetCreatorPtr(void*);
- void SetCreatorData(long);
-
- GlobalWorld GetSavedGlobalWorld() const;
- void SetSavedGlobalWorld(GlobalWorld);
-
- private:
-
- ProcessProc fProc;
- union
- {
- void* fPtr;
- long fLong;
- } fCreatorData; // Storage for the Creator
- TPriorityLink fProcessLink;
- GlobalWorld fSavedWorld;
- };
-
- /* -----------------------------------------------------------------
- INLINE Methods for TOperation
- ----------------------------------------------------------------- */
-
- inline TPriorityLink* TOperation::GetLink()
- {
- return &fProcessLink;
- }
-
- inline unsigned long TOperation::GetTime() const
- {
- return fProcessLink.GetPriority();
- }
-
- inline unsigned long TOperation::GetPriority() const
- {
- return fProcessLink.GetPriority();
- }
-
- inline void TOperation::SetTime(unsigned long msec)
- {
- fProcessLink.SetPriority(msec);
- }
-
- inline void TOperation::SetProcessProc(ProcessProc proc)
- {
- fProc = proc;
- }
-
- inline void TOperation::SetPriority(unsigned long pri)
- {
- fProcessLink.SetPriority(pri);
- }
-
- inline void* TOperation::GetCreatorPtr() const
- {
- return fCreatorData.fPtr;
- }
-
- inline void TOperation::SetCreatorPtr(void* data)
- {
- fCreatorData.fPtr = data;
- }
-
- inline long TOperation::GetCreatorData() const
- {
- return fCreatorData.fLong;
- }
-
- inline void TOperation::SetCreatorData(long data)
- {
- fCreatorData.fLong = data;
- }
-
- inline ProcessProc TOperation::GetProcessProc() const
- {
- return fProc;
- }
-
- inline GlobalWorld TOperation::GetSavedGlobalWorld() const
- {
- return fSavedWorld;
- }
-
- inline void TOperation::SetSavedGlobalWorld(GlobalWorld world)
- {
- fSavedWorld = world;
- }
-
- /**********************************************************************
- ** CLASS TScheduler
- **
- ** This is the base class for all schedulers. It allows for scheduling
- ** TOperations and removing them from the scheduling queue.
- ***********************************************************************/
- // %%% Fix a bug in C++
-
- #define volatile
-
- #define kTSchedulerID "!$sked"
-
- class TScheduler : public TDynamic
- {
- protected:
- TScheduler();
-
- public:
- virtual ~TScheduler();
-
- virtual Boolean Remove(TOperation*) = 0;
- virtual TOperation* Remove(const TMatchObject&) = 0;
- virtual TOperation* RemoveNext() = 0;
- virtual Boolean IsEmpty() const = 0;
-
- virtual void Schedule(TOperation*) = 0;
- virtual void Run() = 0;
-
- Boolean IsSchedulerWorldValid() const;
- GlobalWorld GetSchedulerWorld() const;
- void SetSchedulerWorld(GlobalWorld);
- protected:
- GlobalWorld fSchedulerWorld;
- };
-
- /* -------------------------------------------------------------------------
- Inline Methods for class TScheduler
- ------------------------------------------------------------------------- */
-
- inline Boolean TScheduler::IsSchedulerWorldValid() const
- {
- return fSchedulerWorld != kInvalidWorld;
- }
-
- inline GlobalWorld TScheduler::GetSchedulerWorld() const
- {
- return fSchedulerWorld;
- }
-
- inline void TScheduler::SetSchedulerWorld(GlobalWorld world)
- {
- fSchedulerWorld = world;
- }
-
- /**********************************************************************
- ** CLASS TPriorityScheduler
- **
- ** This class implements a scheduler which simply insures processing
- ** of the TOperations by Priority.
- ***********************************************************************/
-
- #define kTPrioritySchedulerID "!$prsk"
-
- class TPriorityScheduler : public TScheduler
- {
- public:
- TPriorityScheduler(); // autoRun default to false
- TPriorityScheduler(Boolean ifAutoRun);
- virtual ~TPriorityScheduler();
-
- virtual Boolean IsValid() const;
-
- // Returns non-zero if an Operation is removed
- virtual Boolean Remove(TOperation*);
- virtual TOperation* Remove(const TMatchObject&);
- virtual TOperation* RemoveNext();
- virtual Boolean IsEmpty() const;
-
- // Default implementation processes TOperations on the
- // linked list until it is empty, but insures that 2
- // threads are not doing it at the same time. In
- // Non-AutoRun mode, anything scheduled after "Run"
- // is called will not Run until "Run" is called again.
- virtual void Run();
-
- // Default implementation just throws the TOperation on
- // the linked list. If 'ifAutoRun' was set, the Run
- // method is called. Otherwise, someone must manually
- // call Run().
- virtual void Schedule(TOperation*);
-
- virtual void SetAutoRun(Boolean);
-
- protected:
- Boolean IsAutoRun() const;
- Boolean IsSchedulerDead() const;
- void SetSchedulerDead();
-
- TPriorityList fList;
- volatile short fBusy;
- volatile short fFlags;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TPriorityScheduler
- ------------------------------------------------------------------------- */
-
- inline Boolean TPriorityScheduler::IsAutoRun() const
- {
- return fFlags & 1;
- }
-
- inline Boolean TPriorityScheduler::IsSchedulerDead() const
- {
- return fFlags < 0;
- }
-
- inline void TPriorityScheduler::SetSchedulerDead()
- {
- fFlags = -1;
- }
-
- /**********************************************************************
- ** CLASS TSerialScheduler
- **
- ** This class implements a scheduler which simply insures FIFO processing
- ** of the TOperations. It is the same as a TPriorityScheduler, but
- ** sets the priority of the TOperation to kNormalPriority before
- ** scheduling.
- ***********************************************************************/
-
- #define kTSerialSchedulerID "!$srsk"
-
- class TSerialScheduler : public TPriorityScheduler
- {
- public:
- TSerialScheduler(); // autoRun default to false
- TSerialScheduler(Boolean fIfAutoRun);
- virtual ~TSerialScheduler();
-
- virtual void Schedule(TOperation*);
- };
-
- /**********************************************************************
- ** CLASS TThreadScheduler
- **
- ** This class implements a lightweight 'thread' task. In the Macintosh
- ** implementation, it is a TPriorityScheduler.
- ***********************************************************************/
-
- #define kTThreadSchedulerID "slm:sked$thsk"
-
- class TThreadScheduler : public TPriorityScheduler
- {
- public:
-
- TThreadScheduler();
- virtual ~TThreadScheduler();
-
- virtual void Schedule(TOperation*);
-
- protected:
- virtual void Run();
-
- private:
- Ptr fData;
- };
-
- /**********************************************************************
- ** CLASS TTaskScheduler
- **
- ** This class implements a heavy-weight task which can interface to
- ** the operating system. In the Macintosh, it schedules TOperations to
- ** run at System Task time.
- ***********************************************************************/
-
- #define kTTaskSchedulerID "!$task"
-
- class TTaskScheduler : public TPriorityScheduler
- {
- public:
- TTaskScheduler();
- TTaskScheduler(unsigned long pri,
- Boolean runToEmpty = false);
- virtual ~TTaskScheduler();
-
- virtual void Schedule(TOperation*);
-
- virtual void SetPriority(unsigned long);
- void SetRunToEmpty(Boolean);
-
- void ProcessCalled();
-
- protected:
- virtual void Run();
-
- private:
- void InitTaskScheduler(unsigned long);
-
- protected:
- TOperation fOperation;
-
- private:
- ProcPtr fSystem;
- Ptr fData;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TTaskScheduler
- ------------------------------------------------------------------------- */
-
- inline void TTaskScheduler::SetRunToEmpty(Boolean runToEmpty)
- {
- SetAutoRun(runToEmpty);
- }
-
- /**********************************************************************
- ** CLASS TInterruptScheduler
- **
- ** This class is used by all interrupt service routines to process
- ** incoming data. All layers above the interrupt service routines
- ** expect to be able to do any processing they want without fear of
- ** interrupts being locked out. That's what this scheduler insures.
- ***********************************************************************/
-
- #define kTInterruptSchedulerID "slm:sked$insk"
-
- class TInterruptScheduler : public TPriorityScheduler
- {
- public:
-
- TInterruptScheduler();
- virtual ~TInterruptScheduler();
-
- virtual void Schedule(TOperation*);
-
- protected:
- virtual void Run();
-
- private:
- void Process();
-
- Ptr fData;
- };
-
- /**********************************************************************
- ** CLASS TTimeScheduler
- **
- ** This class implements a scheduler which will process TOperations
- ** when a requested amount of time has expired.
- ***********************************************************************/
-
- const unsigned long kMaxScheduledTime = 0xffffffff;
-
- #define kTTimeSchedulerID "slm:sked$tisk"
-
- class TTimeScheduler : public TScheduler
- {
- public:
- TTimeScheduler();
- virtual ~TTimeScheduler();
-
- virtual Boolean IsValid() const;
-
- virtual Boolean Remove(TOperation*);
- virtual TOperation* Remove(const TMatchObject&);
- virtual TOperation* RemoveNext();
- virtual void Schedule(TOperation*);
- virtual Boolean IsEmpty() const;
-
- virtual void SetResolution(unsigned short msecs);
-
- protected:
- virtual void Run();
- virtual unsigned long ProcessTimerEvent();
- virtual TOperation* PrivateRemove(TOperation*, const TMatchObject*);
- virtual void ScheduleCheck(TOperation*);
- virtual Boolean AboutToSchedule(TOperation*);
- virtual TOperation* RemoveCheck(TOperation*, const TMatchObject*);
- virtual TOperation* GetNextOperation();
- virtual void ProcessOperation(TOperation*);
- unsigned long ProcessTimer();
- void Process();
-
- private:
- Ptr fData;
- volatile short fBusy;
- volatile short fDead;
- TPriorityLink* fList;
- TSimpleList fReadyList;
- unsigned short fResolution;
- volatile short fIfProcessing;
-
- protected:
- volatile long fSeed;
- };
-
- #undef volatile
-
- /*******************************************************************************
- ** CLASS TNotifier
- **
- ** This class and its subclasses are used for asynchronous notification
- ** of events.
- ********************************************************************************/
-
- #define kTNotifierID "!$noti"
-
- class TNotifier : public TDynamic
- {
- public:
- TNotifier();
- virtual ~TNotifier();
-
- virtual void Notify(EventCode, OSErr = kNoError,
- void* = NULL) = 0;
-
- protected:
- GlobalWorld fWorld; // Global world when constructed.
- };
-
- /***************************************************************************
- ** CLASS TProcNotifier
- **
- ** This class is the base class for Notifiers that call a "C" procedure
- ** for notification. If the "refPtr" is left NULL, it will be replaced
- ** with a pointer to the TProcNotifier itself.
- ****************************************************************************/
-
- #define kTProcNotifierID "!$pnot"
-
- class TProcNotifier : public TNotifier
- {
- public:
- TProcNotifier(NotifyProc, void* refPtr = NULL);
- TProcNotifier(const TProcNotifier&);
- virtual ~TProcNotifier();
-
- virtual void Notify(EventCode, OSErr = kNoError, void* = NULL);
-
- private:
- NotifyProc fProc;
- void* fPtr;
- };
-
- /***************************************************************************
- ** CLASS TMethodNotifier
- **
- ** This class is the base class for Notifiers that call a method in an object.
- ****************************************************************************/
-
- #define kTMethodNotifierID "!$mnot"
-
- class TMethodNotifier : public TNotifier
- {
- public:
- TMethodNotifier(TDynamic*, NotifyMethod);
- TMethodNotifier(const TMethodNotifier&);
- virtual ~TMethodNotifier();
-
- virtual void Notify(EventCode, OSErr = kNoError, void* = NULL);
-
- TDynamic* GetObject() const;
-
- private:
- TDynamic* fObject;
- NotifyMethod fMethod;
- };
-
- /* -----------------------------------------------------------------
- Inlines for TMethodNotifier
- ----------------------------------------------------------------- */
-
- inline TDynamic* TMethodNotifier::GetObject() const
- {
- return fObject;
- }
-
- /*******************************************************************************
- ** CLASS TMemoryPool
- **
- ** This is the abstract class from which memory allocators should
- ** descend.
- ********************************************************************************/
-
- struct PoolInfo
- {
- size_t fFreeBytes;
- size_t fLargestBlock;
- size_t fMaxUsage;
- size_t fCurSize;
- };
-
- #define kTMemoryPoolID "!$pool"
-
- class TMemoryPool : public TDynamic
- {
- public:
- virtual ~TMemoryPool();
-
- void* operator new(size_t, size_t poolSize,
- ZoneType, MemoryType = kNormalMemory);
- void* operator new(size_t, size_t poolSize,
- void* zone, MemoryType = kNormalMemory);
- void operator delete(void*);
-
- virtual void* Allocate(size_t) = 0;
- virtual void* Reallocate(void*, size_t) = 0;
- virtual void Free(void*) = 0;
- virtual size_t GetSize(void*) const = 0;
-
- virtual Boolean CheckPool() const = 0;
- virtual void GetPoolInfo(PoolInfo&) const;
- virtual void TracePoolInfo() const;
-
- virtual Boolean AddMemoryToPool(size_t);
- virtual void DownsizePool();
- size_t GetCurrentPoolSize() const;
-
- void SetNotifier(TPoolNotifier*);
- TPoolNotifier* GetNotifier() const;
- void SetNotifyMarks(size_t low, size_t high = (size_t)-1L);
-
- static TMemoryPool* RecoverPool(void*);
- static void* AllocateMemory(size_t);
- static void* AllocateMemory(TMemoryPool*, size_t);
- static void* ReallocateMemory(void*, size_t);
- static void FreeMemory(void*);
- static size_t GetMemorySize(void*);
-
- protected:
- TMemoryPool();
- virtual Boolean PrivateAddMemoryToPool(void*, size_t) = 0;
- virtual size_t GetLargestBlockSize() const = 0;
- virtual Boolean RemoveBlockFromPool(void*, size_t);
-
- private:
- TMemoryPool(const TMemoryPool&);
- void operator=(const TMemoryPool&);
-
- private:
- void* fMemList;
-
- protected:
- size_t fSize;
- size_t fLowMark;
- size_t fHighMark;
- size_t fMaxUsed;
- size_t fCurFree;
- void* fZone;
- MemoryType fMemType;
- short fFiller;
- TPoolNotifier* fNotifier;
- unsigned long fSeed;
- TSemaphore fSemaphore;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TMemoryPool
- ----------------------------------------------------------------- */
-
- inline void TMemoryPool::SetNotifyMarks(size_t low, size_t high)
- {
- fLowMark = low;
- fHighMark= high;
- }
-
- inline TPoolNotifier* TMemoryPool::GetNotifier() const
- {
- return fNotifier;
- }
-
- inline void TMemoryPool::SetNotifier(TPoolNotifier* nt)
- {
- fNotifier = nt;
- }
-
- inline size_t TMemoryPool::GetCurrentPoolSize() const
- {
- return fSize;
- }
-
- inline void* TMemoryPool::AllocateMemory(TMemoryPool* thePool, size_t size)
- {
- return thePool->Allocate(size);
- }
-
- inline void* TMemoryPool::AllocateMemory(size_t size)
- {
- return ((TMemoryPool*)::GetDefaultPool())->Allocate(size);
- }
-
- /*******************************************************************************
- ** CLASS TStandardPool
- **
- ** The general purpose interrupt capable storage allocator.
- ********************************************************************************/
-
- const size_t kStandardPoolChunkOverhead = 12;
-
- #define kTStandardPoolID "!$stdp"
-
- class TStandardPool : public TMemoryPool
- {
- public:
- TStandardPool();
- virtual ~TStandardPool();
-
- virtual Boolean IsValid() const;
-
- // TMemoryPool Overrides
-
- virtual void* Allocate(size_t);
- virtual void* Reallocate(void*, size_t);
- virtual void Free(void*);
- virtual size_t GetSize(void*) const;
- virtual Boolean CheckPool() const;
-
- protected:
- virtual Boolean PrivateAddMemoryToPool(void*, size_t);
- virtual size_t GetLargestBlockSize() const;
- virtual Boolean RemoveBlockFromPool(void*, size_t);
-
- TStandardPool(size_t objSize);
-
- private:
- TStandardPool(const TStandardPool&);
- void operator=(const TStandardPool&);
-
- void InitStandardPool(size_t objSize);
-
- Boolean FreeChunks(void*, size_t);
- void InternalFree(void*);
-
- protected:
- void* fList;
-
- private:
- void* fChunks[12];
- };
-
-
- /*******************************************************************************
- ** CLASS TChunkyPool
- **
- ** This class implements a Pool where the memory returned is always
- ** the same size (a "chunk").
- ********************************************************************************/
-
- const size_t kChunkyPoolChunkOverhead = 4;
-
- #define kTChunkyPoolID "!$chkp"
-
- class TChunkyPool : public TMemoryPool
- {
- public:
- TChunkyPool(size_t chunkSize);
- virtual ~TChunkyPool();
-
- virtual Boolean IsValid() const;
-
- // TMemoryPool Overrides
-
- virtual void* Allocate(size_t size);
- virtual void* Reallocate(void*, size_t);
- virtual void Free(void*);
- virtual size_t GetSize(void*) const;
- virtual Boolean CheckPool() const;
-
- protected:
- virtual Boolean PrivateAddMemoryToPool(void*, size_t);
- virtual size_t GetLargestBlockSize() const;
- virtual Boolean RemoveBlockFromPool(void*, size_t);
-
- public:
- // New methods
-
- size_t GetChunkSize() const;
- size_t GetNumberOfChunks() const;
-
- private:
- TChunkyPool(const TChunkyPool&);
- void operator=(const TChunkyPool&);
-
- size_t fNumberOfChunks;
- size_t fChunkSize;
- void* fFreeList;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TChunkyPool
- ----------------------------------------------------------------- */
-
- inline size_t TChunkyPool::GetChunkSize() const
- {
- return fChunkSize;
- }
-
- inline size_t TChunkyPool::GetNumberOfChunks() const
- {
- return fNumberOfChunks;
- }
-
- /*******************************************************************************
- ** CLASS TGrowOperation
- **
- ** See TPoolNotifier below
- ********************************************************************************/
-
- #define kTGrowOperationID "!$gwop"
-
- class TGrowOperation : public TOperation
- {
- public:
- TGrowOperation();
- virtual ~TGrowOperation();
-
- virtual void Process();
-
- size_t fGrowBy;
- Boolean* fOpInUse;
- };
-
- /*******************************************************************************
- ** CLASS TPoolNotifier
- **
- ** Used by TMemoryPools so they can be notified when the pool reaches a low or
- ** high water mark. The TGrowOperation is not processed at interrupt time so it
- ** is always safe for it to grow the pool.
- ********************************************************************************/
-
- #define kTPoolNotifierID "!$plnt"
-
- class TPoolNotifier : public TNotifier
- {
- public:
- TPoolNotifier(unsigned short growBy = 10,
- unsigned short minGrow = 128);
- virtual ~TPoolNotifier();
-
- virtual void Notify(EventCode, OSErr = kNoError, void* = NULL);
- virtual size_t GrowBy(TMemoryPool*, size_t);
-
- private:
- void InitNotifier(unsigned short, unsigned short);
-
- TGrowOperation fOperation;
- unsigned short fMinSize;
- unsigned short fGrowBy;
- Boolean fOpInUse;
- };
-
- /**********************************************************************
- ** CLASS TArbitrator
- ***********************************************************************/
-
- #define kTArbitratorID "!$arbt"
-
- #define kRequestIDPrefix '?'
- #define kRequestIDPrefixSize 1
-
- enum TokenRequestType
- {
- kInvalidTokenRequest, kRequestTokenRequest,
- kExclusiveTokenRequest, kSharedTokenRequest
- };
-
- class TArbitrator : public THashObject
- {
- friend class TToken;
- public:
- TArbitrator(TStandardPool* = NULL,
- size_t defSize = 0);
- virtual ~TArbitrator();
-
- virtual OSErr RegisterObject(char* theID, void* theObject);
- virtual void* UnregisterObject(char* theID);
- virtual void* LookupObject(char* theID);
-
- virtual OSErr RegisterToken(TToken*);
- virtual TToken* GetToken(char* theID, TokenRequestType);
-
- virtual TRequestToken* PassiveRequest(char* theID, TokenRequestType, TNotifier* = NULL, Boolean registerIfFirst = false);
- virtual TRequestToken* ActiveRequest(char* theID, TokenRequestType, TNotifier* = NULL, Boolean registerIfFirst = false);
- virtual TRequestToken* GetRequest(char* theID);
-
- virtual Boolean NotifyOwners(TRequestToken* theRequest);
- virtual unsigned long Hash(const void*) const;
-
- private: // methods
- virtual void ReleaseToken(TToken* theToken);
- virtual TToken* NewToken(char* theID, void* = NULL);
- virtual TRequestToken* NewRequestToken(char* theID, TokenRequestType, TNotifier* = NULL);
- virtual void UnregisterToken(TToken*);
-
- private: // data
- TCollection* fHashList;
- };
-
- /**********************************************************************
- ** Class TTokenNotification (inline methods only)
- ***********************************************************************/
-
- class TTokenNotification
- {
- public:
- TTokenNotification(TToken*, TRequestToken*);
- ~TTokenNotification();
- TToken* GetToken();
- TRequestToken* GetRequestToken();
- private:
- TToken* fToken;
- TRequestToken* fRequestToken;
- };
-
- /* -----------------------------------------------------------------
- inline methods for TTokenNotification
- ----------------------------------------------------------------- */
-
- inline TToken* TTokenNotification::GetToken()
- {
- return fToken;
- }
-
- inline TRequestToken* TTokenNotification::GetRequestToken()
- {
- return fRequestToken;
- }
-
-
- /**********************************************************************
- ** CLASS TToken
- ***********************************************************************/
-
- #define kTTokenID "!$tokn"
-
- class TToken : public TMatchObject
- {
- friend class TArbitrator;
-
- public:
- virtual ~TToken();
-
- virtual Boolean Get(TokenRequestType);
- virtual void Release();
- virtual Boolean Request(TRequestToken*);
- virtual Boolean Notify(TRequestToken*);
- virtual TokenRequestType GetRequestType() const;
-
- char* GetID() const;
-
- void* GetObject() const;
- void SetObject(void* theObject);
-
- TNotifier* GetNotifier() const;
- void SetNotifier(TNotifier*);
-
- virtual Boolean IsEqual(const void*) const;
- virtual unsigned long Hash() const;
-
- long GetUseCount() const;
-
- protected:
- TToken();
-
- private:
- virtual void ReallyRelease();
-
- protected:
- TSemaphore fSemaphore;
- char* fID;
- void* fObject;
- TArbitrator* fArbitrator;
- long fUseCount;
- TNotifier* fNotifier;
- };
-
- /* -----------------------------------------------------------------
- inlines for TToken
- ----------------------------------------------------------------- */
-
- inline char* TToken::GetID() const
- {
- return fID;
- }
-
- inline void* TToken::GetObject() const
- {
- return fObject;
- }
-
- inline void TToken::SetObject(void* theObject)
- {
- fObject = theObject;
- }
-
- inline TNotifier* TToken::GetNotifier() const
- {
- return fNotifier;
- }
-
- inline void TToken::SetNotifier(TNotifier* theNotifier)
- {
- fNotifier = theNotifier;
- }
-
- inline long TToken::GetUseCount() const
- {
- return fUseCount;
- }
-
- /**********************************************************************
- ** CLASS TRequestToken
- ***********************************************************************/
-
- #define kTRequestTokenID "!$rqtk"
-
- class TRequestToken : public TToken
- {
- friend class TArbitrator;
-
- public:
- virtual ~TRequestToken();
-
- virtual Boolean IsEqual(const void*) const;
- virtual unsigned long Hash() const;
-
- virtual Boolean Give(TToken* theToken);
- virtual TToken* Exchange();
- virtual void RequestAgain();
-
- virtual TokenRequestType GetRequestType() const;
- virtual void SetRequestType(TokenRequestType);
-
- Boolean IsTokenRegistered() const;
-
- private:
- TRequestToken();
-
- private: // data
- Boolean fTokenRegistered;
- Boolean fActive;
- TokenRequestType fRequestType;
- };
-
- /* -----------------------------------------------------------------
- inlines for TRequestToken
- ----------------------------------------------------------------- */
-
- inline Boolean TRequestToken::IsTokenRegistered() const
- {
- return fTokenRegistered;
- }
-
-
- /*******************************************************************************
- ** class TClassInfo
- ********************************************************************************/
-
- #define kTClassInfoID "slm:supp$clif"
-
- class TClassInfo : public TIterator
- {
- friend class TLibraryManager;
-
- public:
- virtual ~TClassInfo();
-
- // TIterator overrides
- virtual void Reset();
- virtual void* Next(); // safe to cast to TClassID* or char*
-
- virtual Boolean IterationComplete() const;
- virtual Boolean RemoveCurrentObject(); // do nothing instead
-
- // TClassInfo methods
- void SetBaseClassID(const TClassID& classID);
-
- TClassID* GetClassID();
- TClassID* GetClassParentID();
- TConfiguration* GetClassConfiguration() const;
-
- Boolean GetClassNewObjectFlag() const;
- Boolean GetClassPreloadFlag() const;
- size_t GetClassSize() const;
-
- private:
- TClassInfo();
-
- private:
- TClassID fBaseClassID;
- TClassID fClassID;
- TClassID fParentID;
- TConfiguration* fConfiguration;
- Boolean fNewObjectFlag;
- Boolean fPreloadFlag;
- size_t fSize;
- };
-
- /* -------------------------------------------------------------------------
- inline methods of TClassInfo
- ------------------------------------------------------------------------- */
-
- inline void TClassInfo::SetBaseClassID(const TClassID& classID)
- {
- fBaseClassID = classID;
- Reset();
- }
-
- inline TClassID* TClassInfo::GetClassID()
- {
- return &fClassID;
- }
-
- inline TClassID* TClassInfo::GetClassParentID()
- {
- return &fParentID;
- }
-
- inline TConfiguration* TClassInfo::GetClassConfiguration() const
- {
- return fConfiguration;
- }
-
-
- inline Boolean TClassInfo::GetClassNewObjectFlag() const
- {
- return fNewObjectFlag;
- }
-
- inline Boolean TClassInfo::GetClassPreloadFlag() const
- {
- return fPreloadFlag;
- }
-
- inline size_t TClassInfo::GetClassSize() const
- {
- return fSize;
- }
-
- /**********************************************************************
- ** Class TLibraryFile
- **
- ** Used mainly to get resources out of a library. A C interface is also
- ** provided in TLibraryManagerUtilities.h
- ***********************************************************************/
-
- #define kTLibraryFileID "!$lfil"
-
- extern "C" TLibraryFile* GetLocalLibraryFile();
-
- class TLibraryFile : public TDynamic
- {
- public:
- virtual ~TLibraryFile();
-
- // New Methods
-
- virtual OSErr Preflight(short& savedRefNum) = 0;
- virtual OSErr Postflight(short savedRefNum) = 0;
-
- virtual Handle GetSharedResource(ResType theType, short theID) = 0;
- virtual Handle GetSharedIndResource(ResType theType, short index) = 0;
- virtual Handle GetSharedNamedResource(ResType theType, ConstStr255Param name) = 0;
-
- virtual void ReleaseSharedResource(Handle) = 0;
- virtual long CountSharedResources(ResType theType) = 0;
-
- virtual size_t GetSharedResourceUseCount(Handle) const = 0;
-
- virtual OSErr CloseLibrary() = 0;
- virtual long GetRefNum() const = 0;
- virtual long GetFileID() const = 0;
- virtual short GetVolumeRefNum() const = 0;
-
- protected:
- TLibraryFile();
- };
-
- /**********************************************************************
- ** CLASS TBitmap
- ***********************************************************************/
-
- #define kTBitmapID "slm:supp$bmap"
-
- class TBitmap : public TDynamic
- {
- public:
- TBitmap(size_t numBits, TMemoryPool* pool);
- TBitmap(Ptr bits, size_t nBits);
- virtual ~TBitmap();
-
-
- // NOTE: There is no ErrorChecking on these first 3 calls.
-
- virtual Boolean SetBit(size_t);
- virtual Boolean ClearBit(size_t);
- virtual Boolean TestBit(size_t);
-
- // These return -1 if no free bits
-
- virtual long SetFirstClearBit();
- virtual long SetFirstClearBit(size_t, size_t);
-
- private:
- void InitBitmap(size_t numBits, TMemoryPool* pool);
- void InitBitmap(Ptr bits, size_t nBits);
-
- unsigned char* fBits;
- size_t fNumberBits;
- Boolean fIsNewd;
- };
-
- /**********************************************************************
- ** CLASS TDoubleLong
- **
- ** Implements a TDynamic double long (64 bits). Normally this is used
- ** as a superclass for some other class which has a 64-bit value as its
- ** comparable/hashing value (the default hash value is the low 32-bits).
- ***********************************************************************/
-
- #define kTDoubleLongID "slm:supp$dbll"
-
- class TDoubleLong : public TMatchObject
- {
- public:
- TDoubleLong(const TDoubleLong&);
- TDoubleLong(unsigned long low, long hi);
- TDoubleLong(long l);
- TDoubleLong();
- virtual ~TDoubleLong();
-
- virtual OSErr Inflate(TFormattedStream&);
- virtual OSErr Flatten(TFormattedStream&) const;
-
- virtual Boolean IsEqual(const void*) const;
- virtual unsigned long Hash() const;
-
- virtual operator double() const;
- operator unsigned long() const;
-
- virtual TDoubleLong& Add(const TDoubleLong&);
- virtual TDoubleLong& Subtract(const TDoubleLong&);
- virtual TDoubleLong& Multiply(const TDoubleLong&);
- virtual TDoubleLong& Divide(const TDoubleLong&);
- virtual TDoubleLong& Modulo(const TDoubleLong&);
- virtual TDoubleLong RShift(unsigned short) const;
- virtual TDoubleLong LShift(unsigned short) const;
- virtual TDoubleLong& Negate();
- virtual short Compare(const void*) const;
-
- TDoubleLong& operator=(const TDoubleLong&);
- TDoubleLong& operator+=(const TDoubleLong&);
- TDoubleLong& operator-=(const TDoubleLong&);
- TDoubleLong& operator*=(const TDoubleLong&);
- TDoubleLong& operator/=(const TDoubleLong&);
- TDoubleLong& operator%=(const TDoubleLong&);
- TDoubleLong& operator&=(const TDoubleLong&);
- TDoubleLong& operator|=(const TDoubleLong&);
- TDoubleLong& operator^=(const TDoubleLong&);
- TDoubleLong& operator~();
- TDoubleLong& operator-();
-
- TDoubleLong operator+(const TDoubleLong&) const;
- TDoubleLong operator-(const TDoubleLong&) const;
- TDoubleLong operator*(const TDoubleLong&) const;
- TDoubleLong operator/(const TDoubleLong&) const;
- TDoubleLong operator%(const TDoubleLong&) const;
- TDoubleLong operator&(const TDoubleLong&) const;
- TDoubleLong operator|(const TDoubleLong&) const;
- TDoubleLong operator^(const TDoubleLong&) const;
-
- TDoubleLong operator<<(unsigned short) const;
- TDoubleLong operator>>(unsigned short) const;
-
- Boolean operator>(const TDoubleLong&) const;
- Boolean operator<(const TDoubleLong&) const;
- Boolean operator<=(const TDoubleLong&) const;
- Boolean operator>=(const TDoubleLong&) const;
- Boolean operator==(const TDoubleLong&) const;
- Boolean operator!=(const TDoubleLong&) const;
-
- protected:
- long fHiBits;
- unsigned long fLoBits;
- };
-
- /* -----------------------------------------------------------------
- INLINE Methods for TDoubleLong
- ----------------------------------------------------------------- */
-
- inline TDoubleLong::operator unsigned long() const
- {
- return fLoBits;
- }
-
- inline TDoubleLong TDoubleLong::operator &(const TDoubleLong& val) const
- {
- return TDoubleLong(fLoBits & val.fLoBits, fHiBits & val.fHiBits);
- }
-
- inline TDoubleLong& TDoubleLong::operator =(const TDoubleLong& val)
- {
- fHiBits = val.fHiBits;
- fLoBits = val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong& TDoubleLong::operator +=(const TDoubleLong& val)
- {
- return Add(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator -=(const TDoubleLong& val)
- {
- return Subtract(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator *=(const TDoubleLong& val)
- {
- return Multiply(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator /=(const TDoubleLong& val)
- {
- return Divide(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator %=(const TDoubleLong& val)
- {
- return Modulo(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator &=(const TDoubleLong& val)
- {
- fHiBits &= val.fHiBits;
- fLoBits &= val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong& TDoubleLong::operator |=(const TDoubleLong& val)
- {
- fHiBits |= val.fHiBits;
- fLoBits |= val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong& TDoubleLong::operator ^=(const TDoubleLong& val)
- {
- fHiBits ^= val.fHiBits;
- fLoBits ^= val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong TDoubleLong::operator +(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- return (&temp)->Add(val);
- }
-
- inline TDoubleLong TDoubleLong::operator -(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- return (&temp)->Subtract(val);
- }
-
- inline TDoubleLong TDoubleLong::operator *(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- return (&temp)->Multiply(val);
- }
-
- inline TDoubleLong TDoubleLong::operator /(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- return (&temp)->Divide(val);
- }
-
- inline TDoubleLong TDoubleLong::operator %(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- return (&temp)->Modulo(val);
- }
-
- inline TDoubleLong TDoubleLong::operator |(const TDoubleLong& val) const
- {
- return TDoubleLong(fLoBits | val.fLoBits, fHiBits | val.fHiBits);
- }
-
- inline TDoubleLong TDoubleLong::operator ^(const TDoubleLong& val) const
- {
- return TDoubleLong(fLoBits ^ val.fLoBits, fHiBits ^ val.fHiBits);
- }
-
- inline TDoubleLong& TDoubleLong::operator~()
- {
- fHiBits = ~fHiBits;
- fLoBits = ~fLoBits;
- return *this;
- }
-
- inline TDoubleLong& TDoubleLong::operator -()
- {
- return Negate();
- }
-
- inline TDoubleLong TDoubleLong::operator >>(unsigned short val) const
- {
- return RShift(val);
- }
-
- inline TDoubleLong TDoubleLong::operator <<(unsigned short val) const
- {
- return LShift(val);
- }
-
- inline Boolean TDoubleLong::operator ==(const TDoubleLong& val) const
- {
- return fLoBits == val.fLoBits && fHiBits == val.fHiBits;
- }
-
- inline Boolean TDoubleLong::operator !=(const TDoubleLong& val) const
- {
- return fLoBits != val.fLoBits || fHiBits != val.fHiBits;
- }
-
- inline Boolean TDoubleLong::operator >(const TDoubleLong& val) const
- {
- return Compare(&val) > 0;
- }
-
- inline Boolean TDoubleLong::operator >=(const TDoubleLong& val) const
- {
- return Compare(&val) >= 0;
- }
-
- inline Boolean TDoubleLong::operator <(const TDoubleLong& val) const
- {
- return Compare(&val) < 0;
- }
-
- inline Boolean TDoubleLong::operator <=(const TDoubleLong& val) const
- {
- return Compare(&val) <= 0;
- }
-
- /**********************************************************************
- ** CLASS THashDoubleLong
- **
- ** Class to compare a TDoubleLong. The 'const Ptr' parameter is a
- ** pointer to a TDoubleLong object.
- ***********************************************************************/
-
- #define kTHashDoubleLongID "slm:supp$hdbl"
-
- class THashDoubleLong : public THashObject
- {
- public:
- THashDoubleLong();
- virtual ~THashDoubleLong();
-
- virtual unsigned long Hash(const void*) const;
- };
-
- /**********************************************************************
- ** CLASS TTime
- **
- ** This is the superclass for all Time-related classes. Internally,
- ** all times are stored as microSeconds, and the casting operators
- ** for the TTime class return values converted to microseconds.
- ***********************************************************************/
-
- #define kTTimeID "slm:supp$time"
-
- class TTime : public TDoubleLong
- {
- public:
- TTime();
- TTime(unsigned long microseconds);
- TTime(const TDoubleLong&);
- TTime(const TTime&);
- virtual ~TTime();
-
- void SetTime(const TTime&);
-
- void SetMicroseconds(unsigned long);
- virtual void SetMilliseconds(unsigned long);
- virtual void SetSeconds(unsigned long);
-
- unsigned long GetMicroseconds() const;
- virtual unsigned long GetMilliseconds() const;
- virtual unsigned long GetSeconds() const;
- };
-
- /* -----------------------------------------------------------------
- INLINE Methods for TTime
- ----------------------------------------------------------------- */
-
- inline void TTime::SetTime(const TTime& time)
- {
- fLoBits = time.fLoBits;
- fHiBits = time.fHiBits;
- }
-
- inline void TTime::SetMicroseconds(unsigned long val)
- {
- fLoBits = val;
- fHiBits = 0;
- }
-
- inline unsigned long TTime::GetMicroseconds() const
- {
- return fLoBits;
- }
-
- /**********************************************************************
- ** CLASS TMicroseconds
- ***********************************************************************/
-
- #define kTMicrosecondsID "slm:supp$mics"
-
- class TMicroseconds : public TTime
- {
- public:
- TMicroseconds();
- TMicroseconds(unsigned long msecs);
- ~TMicroseconds();
-
- operator unsigned long() const;
- virtual operator double() const;
-
- private:
- TMicroseconds(const TMicroseconds&);
- void operator=(const TMicroseconds&);
- };
-
- /* -----------------------------------------------------------------
- INLINE Methods for TMicroseconds
- ----------------------------------------------------------------- */
-
- inline TMicroseconds::operator unsigned long() const
- {
- return GetMicroseconds();
- }
-
- /**********************************************************************
- ** CLASS TMilliseconds
- ***********************************************************************/
-
- #define kTMillisecondsID "slm:supp$mils"
-
- class TMilliseconds : public TTime
- {
- public:
- TMilliseconds();
- TMilliseconds(unsigned long msecs);
- ~TMilliseconds();
-
- operator unsigned long() const;
- virtual operator double() const;
-
- private:
- TMilliseconds(const TMilliseconds&);
- void operator=(const TMilliseconds&);
- };
-
- /* -----------------------------------------------------------------
- INLINE Methods for TMilliseconds
- ----------------------------------------------------------------- */
-
- inline TMilliseconds::operator unsigned long() const
- {
- return GetMilliseconds();
- }
-
- /**********************************************************************
- ** CLASS TSeconds
- ***********************************************************************/
-
- #define kTSecondsID "slm:supp$secs"
-
- class TSeconds : public TTime
- {
- public:
- TSeconds();
- TSeconds(unsigned long secs);
- ~TSeconds();
-
- operator unsigned long() const;
- virtual operator double() const;
-
- private:
- TSeconds(const TSeconds&);
- void operator=(const TSeconds&);
- };
-
- /* -----------------------------------------------------------------
- INLINE Methods for TSeconds
- ----------------------------------------------------------------- */
-
- inline TSeconds::operator unsigned long() const
- {
- return GetSeconds();
- }
-
- /**********************************************************************
- ** CLASS TTimeStamp
- ***********************************************************************/
-
- #define kTTimeStampID "slm:supp$tstm"
-
- class TTimeStamp : public TTime
- {
- public:
- TTimeStamp();
- virtual ~TTimeStamp();
-
- virtual void SetTimeStamp();
-
- private:
- TTimeStamp(const TTimeStamp&);
- void operator=(const TTimeStamp&);
- };
-
- /**********************************************************************
- ** CLASS TStopwatch
- ***********************************************************************/
-
- #define kTStopwatchID "slm:supp$stpw"
-
- class TStopwatch : public TTimeStamp
- {
- public:
- TStopwatch();
- virtual ~TStopwatch();
-
- virtual void Reset();
-
- virtual unsigned long ElapsedMicroseconds() const;
- virtual unsigned long ElapsedMilliseconds() const;
- virtual unsigned long ElapsedSeconds() const;
-
- private:
- TStopwatch(const TStopwatch&);
- void operator=(const TStopwatch&);
- };
-
- /*******************************************************************************
- ** CLASS TTraceLog
- **
- ** An object for doing debug tracing with.
- ********************************************************************************/
-
- #define kTTraceLogID "slm:dbug$tlog"
-
- class TTraceLog : public TDynamic
- {
- public:
- TTraceLog();
- virtual ~TTraceLog();
-
- virtual void Trace(char *formatStr, ...) const;
-
- // New methods
-
- Boolean IsTraceLogOn() const;
- void TraceLogOn();
- void TraceLogOff();
-
- virtual void TraceFormatted(char* outstr) = 0;
- virtual void TraceUnformatted(void* argp);
-
- protected:
- void SetTracePool(TStandardPool*);
- TStandardPool* GetTracePool() const;
-
- private:
- TTraceLog(const TTraceLog&);
- void operator=(const TTraceLog&);
-
- Boolean fTracing;
- TStandardPool* fTracePool;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TTraceLog
- ----------------------------------------------------------------- */
-
- inline Boolean TTraceLog::IsTraceLogOn() const
- {
- return fTracing;
- }
-
- inline void TTraceLog::TraceLogOn()
- {
- if (fTracePool != NULL)
- fTracing = true;
- }
-
- inline void TTraceLog::TraceLogOff()
- {
- fTracing = false;
- }
-
- inline void TTraceLog::SetTracePool(TStandardPool* pool)
- {
- fTracePool = pool;
- }
-
- inline TStandardPool* TTraceLog::GetTracePool() const
- {
- return fTracePool;
- }
-
- /*******************************************************************************
- ** EXCEPTION Handling
- **
- ** Some RULES:
- ** 1) Never propogate a failure outside of a constructor or destructor.
- ** If your constructor or destructor can call something which fails, it
- ** _must_ EXCEPT the failure and not re-propogate it.
- ** 2) Never create an object inside of a "try" block which you cannot
- ** destroy (especially an auto object).
- ** 3) Falling through the end of a "EXCEPT" will re-throw the exception.
- ** You must "break" out of a EXCEPT in order not to re-throw it.
- ** 4) if you are going to just "fall" out of the "EXCEPT" to re-throw
- ** the exception, you must manually call the destructors of any
- ** auto objects that are still in scope, before falling out!
- ** 5) Any variables that are changed inside the "try", and which are tested
- ** inside the "EXCEPT" must be declared "volatile" (Use the VOLATILE macro
- ** below until C++ and volatile work!)
- ** 6) Never call Failure while an auto variable is in scope - it's
- ** destructor will not be called unless you call it manually.
- ********************************************************************************/
-
- #ifndef __SETJMP__
- #include <SetJmp.h>
- #endif
-
- struct TException
- {
- static void Push(TException*);
- static TException* Pop();
-
- TException* fPrev;
- jmp_buf fBuffer;
- char* fMessage;
- void* fReserved;
- OSErr fError;
- };
-
-
- /* -----------------------------------------------------------------
- Some important functions for exception handling
- ----------------------------------------------------------------- */
-
- void Failure(OSErr err, const char* msg=NULL);
-
- inline void FailNULL(void* val, OSErr err, const char* msg=NULL)
- {
- if (val == 0)
- Failure(err, msg);
- }
-
- inline void FailError(OSErr err, const char* msg=NULL)
- {
- if (err != kNoError)
- Failure(err, msg);
- }
-
- #define ErrorCode() (envExcept001.fError)
- #define ErrorMessage() (envExcept001.fMessage)
- #define Volatile(x) ((void) &x)
-
- #if qDebug
- #define DebugFailure(err, msg) Failure(err, msg)
- #define DebugFailError(err, msg) FailError(err, msg)
- #define DebugFailNULL(ptr, err, msg) FailNULL(ptr, err, msg)
- #else
- #define DebugFailure(err, msg) Failure(err, NULL)
- #define DebugFailError(err, msg) FailError(err, NULL)
- #define DebugFailNULL(ptr, err, msg) FailNULL(ptr, err, NULL)
- #endif
-
-
- /* -----------------------------------------------------------------
- The TRY/EXCEPT macros
- ----------------------------------------------------------------- */
-
- #define TRY \
- TException envExcept001; \
- envExcept001.Push(&envExcept001); \
- TException* envExcept002 = &envExcept001; \
- if (!setjmp(envExcept001.fBuffer)) { \
- do {
-
- #define EXCEPT \
- } while (0); \
- TException::Pop(); \
- } \
- else \
- for (; (1); Failure(envExcept001.fError))
-
- /*******************************************************************************
- ** Some inlines that rely on other inlines so we just do them here to preven
- ** circular dependency problems.
- ********************************************************************************/
-
- /* -------------------------------------------------------------------------
- Inline methods for TArray
- ------------------------------------------------------------------------- */
-
- inline TStandardPool* TArray::GetGrowPool() const
- {
- return (TStandardPool*)TMemoryPool::RecoverPool(fArray);
- }
-
- #endif